package cn.iocoder.yudao.module.vote.controller.app.voteHead;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.vote.controller.admin.voteHead.vo.VoteHeadSaveReqVO;
import cn.iocoder.yudao.module.vote.controller.app.voteHead.vo.VoteResultRespVO;
import cn.iocoder.yudao.module.vote.service.voteHead.VoteHeadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 投票头")
@RestController
@RequestMapping("/vote/head")
@Validated
public class VoteHeadAppController {

    @Resource
    private VoteHeadService headService;


    @PostMapping("/vote")
    @Operation(summary = "创建投票")
    public CommonResult<Boolean> createVote(@RequestBody VoteHeadSaveReqVO createReqVO) {
        headService.vote(createReqVO);
        return success(true);
    }

    @GetMapping("/query")
    @Operation(summary = "查看投票")
    public CommonResult<VoteResultRespVO> queryVote(@RequestParam("id") Long id) {
        return success(headService.queryVote(id));
    }

}
